var wsServer=require("ws").Server;
var handler=require("./handler");
main();
function main(){
    var args = process.argv.splice(2);
    if(args==null||args.length==0){
        console.log("请输入端口");
        return;
    }
    var port=args[0];
    var wss=new wsServer({port:port});
    wss.on('connection',function(ws){
        ws.on('open',function(){
        });
        ws.on('message',function(message){
            console.log("收到消息:"+message);
            if(typeof  message =="string"){
                var obj=JSON.parse(message);
                try {
                    handler.exec(ws,obj.code,obj.data);
                }catch (e) {
                    console.error(e);
                }
            }
        });
        ws.on('close',function(){

        })
    })
    console.log("服务启动完成端口:"+port);
}

